<template>
  <el-container style="height: 500px;  min-height: 100vh;">

    <el-aside :width="sideWidth+'px'"
              style="background-color: rgb(238, 241, 246); height: 100%; box-shadow:rgba(0 21 41 0.35) 2px 0 6px;">
      <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow"/>
    </el-aside>

    <el-container>
      <el-header style="font-size: 12px;border-bottom: 1px solid #ccc;line-height: 60px;">
        <Header :collapseBtnClas="collapseBtnClas" :collapse="isCollapse" :user="user"/>
      </el-header>

      <el-main>
        <router-view @refreshUser="getUser"/>
      </el-main>

    </el-container>
  </el-container>
</template>

<script>
import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  name: 'Manege',
  components: {
    Header,
    Aside
  },
  data() {
    return {
      collapseBtnClas: 'el-icon-s-fold',
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      user: {}
    }
  },
  created() {
    this.getUser()
  },
  methods: {
    collapse() { //点击收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) { //收缩
        this.sideWidth = 64
        this.collapseBtnClas = 'el-icon-s-unfold'
        this.logoTextShow = false
      } else {  //展开
        this.sideWidth = 200
        this.collapseBtnClas = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },
    getUser() {
      let username=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")).username:""
      // 从后台获取User数据
      this.request.get("/user/username/" + username).then(res => {
        // 重新赋值后台的最新User数据
        this.user=res.data
      })
    },
  }
}
</script>



